
#include <chrono>
#include <random>
#include <iostream>
using namespace std;

#include "Global.h"
#include "ThreadPool.hpp"

void ThreadPoolTest();

void begin()
{
    cout << "Begin \n";
}

void end()
{
    cout << "End \n";
}

CONSTRUCTOR_FUNCTION(begin)
DESTRUCTOR_FUNCTION(end)

int main(int argc, char const *argv[])
{
    if (1)
    {
        // 对浮点数四舍五入
        float ff = 1.41432432;
        std::cout << "After Round:\t" << Round(ff) << std::endl;
        ff = 1.71432432;
        std::cout << "After Round:\t" << Round(ff) << std::endl;

        // default_random_engine engine;
        // random_device sd;
        // minstd_rand linearRan(sd());
        // uniform_int_distribution<int> dis1(0, 100);
        int a = 50,
            b = 45,
            c = 99;
        std::cout << "a:\t" << a << std::endl;
        std::cout << "b:\t" << b << std::endl;
        std::cout << "c:\t" << c << std::endl;
        // Bound
        std::cout << "After Bound:\t" << Bound(a, b, c) << std::endl;
    }

    // ThreadPoolTest();
    return 0;
}

void ThreadPoolTest()
{
    cout << __FUNCTION__ << endl;

    ThreadPool tp(10);

    for (unsigned int i = 0; i < 20; ++i)
    {
        tp.enqueue([i](void) -> void
                   {
            char buf[36] = {'\0'};
            snprintf(buf,36, "thread:%d\n", i);
            std::this_thread::sleep_for(std::chrono::milliseconds(100));
            cout << std::hex << std::this_thread::get_id() << std::string(buf); });
    }
}